package com.xzy.fruitmall.controller;

import com.alibaba.fastjson.JSONArray;
import com.xzy.fruitmall.GoodsService;
import com.xzy.fruitmall.entity.GoodsInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sgg")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    private String goodsName = "default";

    @GetMapping(value = {"/allGoods"})
    public String allGoods(){
        String str = "{";
        str+= JSONArray.toJSONString(goodsService.findAllGoods())+"}";
        return str;
    }

    @GetMapping(value = {"/findGoodsByName/{goodsName}"})
    public String findGoodsByName(@PathVariable("goodsName") String goodsName){
        //String str = "{";
        String str=JSONArray.toJSONString(goodsService.findGoodsByName(goodsName));//+"}";
        return str;
    }

    @DeleteMapping(value = {"/deleteGoodsById/{goodsId}"})
    public String deleteGoodsById(@PathVariable("goodsId") int goodsId){
        goodsService.deleteGoodsById(goodsId);
        String str = "{";
        str+= JSONArray.toJSONString(goodsService.findAllGoods())+"}";
        return str;
    }

    @GetMapping(value = {"/findGoodsById/{goodsId}"})
    public String findGoodsById(@PathVariable("goodsId") int goodsId){
        //String str = "{";
        String str=JSONArray.toJSONString(goodsService.findGoodsById(goodsId));//+"}";
        return str;
    }

    @PutMapping(value = {"/updateGoods/{goodsName}/{goodsPrice}/{goodsSort}/{goodsDescription}" +
            "/{goodsStock}/{goodsThreshold}/{goodsOrigin}/{storageConditions}/{goodsBrand}/{picPath}/{goodsId}"})
    public String updateGoods(String goodsName,int goodsPrice,String goodsSort,String goodsDescription,int goodsStock,
                              int goodsThreshold,String goodsOrigin,String storageConditions,String goodsBrand,
                              String picPath,int goodsId){
        GoodsInfo gi;
        String str;
        return null;
    }
}
